//
//  CMDBRegisterParam.swift
//  CMDB
//
//  Created by 王磊 on 17/4/5.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

class CMDBRegisterParam: CMDBDeviceParam {
    
    var phone: String = "" // 11位 手机号
    
    var vcode: String = "" // 4位 验证码
    
    var inviteCode: String = "" // 邀请码 规则未定
    
    var name: String = "" // 姓名
    
    var useNames: String {
        
        guard useTempNames.count != 0 else {
            return ""
        }
        
        return CMDBRegisterParam.castNamesToString(useTempNames)
    }// 曾用名
    
    var useTempNames: Array<String> = []
    
    var email: String = "" // 邮箱
    
    var pwd: String = "" // 密码
    
    var submitPwd: String = "" // 确认密码
    
    var birthday: String = "" // 生日
    
    var trade: String = ""
    
    var gender: String { //  性别
        return "\(genderType.rawValue)"
    }
    var genderType: CMDBGenderType = CMDBGenderType.Mail
}
extension CMDBRegisterParam {
    override func URLString() -> String {
        return CMDB_Http_Formal_Domain + "/app/user/\(server_Version)/reg?"
    }
}
extension CMDBRegisterParam {
    
    static func castNamesToString(arr: Array<String>) -> String {
        
        let mutable = NSMutableArray()
        
        _ = arr.map({
            
            mutable.addObject($0)
            
        })
        
        let jsonData = try? NSJSONSerialization.dataWithJSONObject(mutable, options: .PrettyPrinted)
        
        guard let jsonTemp = jsonData else {
            
            return ""
        }
        let jsonStr = String(data: jsonTemp,encoding: NSUTF8StringEncoding)
        
        return jsonStr!
    }
}
